package ds

import (
	"chrent.com/ServiceManage/boot/setting"
	"chrent.com/ServiceManage/models"
	"chrent.com/ServiceManage/utils"
	"github.com/golang-module/dongle"
	"github.com/jinzhu/gorm"
	pm2app "github.com/ntt360/pmon2/app"
)

func Db() *gorm.DB {
	pm2app.Instance(utils.GetPm2Conf())
	if setting.Conf.Production {
		return pm2app.Db()
	}
	return pm2app.Db().LogMode(true)
}
func InitDb() {
	if !Db().HasTable(&models.User{}) {
		Db().CreateTable(&models.User{})
		Db().Save(&models.User{
			Email:    "admin@admin.com",
			Name:     "admin",
			Password: dongle.Sign.FromString("Abc123456").ByBcrypt().ToRawString(),
		})
	}
	if !Db().HasTable(&models.Task{}) {
		Db().CreateTable(&models.Task{})
	}
}
